package com.jr.service.impl;

import com.jr.mapper.NotificationMapper;
import com.jr.pojo.Notification;
import com.jr.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class NotificationServiceImpl implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;

    @Override
    public boolean sendNotification(Notification notification) {
        return notificationMapper.insertNotification(notification) > 0;
    }

    @Override
    public ArrayList<Notification> getNotificationsByUserId(Integer userId) {
        return notificationMapper.selectByUserId(userId);
    }

    @Override
    public ArrayList<Notification> getNotificationsByUserIdWithPagination(Integer userId, Integer pageIndex, Integer pageSize) {
        int offset = (pageIndex - 1) * pageSize;
        return notificationMapper.selectByUserIdWithPagination(userId, offset, pageSize);
    }

    @Override
    public int getNotificationCount(Integer userId) {
        return notificationMapper.selectCountByUserId(userId);
    }

    @Override
    public boolean markAsRead(Integer notificationId) {
        return notificationMapper.updateReadStatus(notificationId, true) > 0;
    }

    @Override
    public int getUnreadCount(Integer userId) {
        return notificationMapper.selectUnreadCount(userId);
    }

    @Override
    public boolean deleteNotification(Integer notificationId) {
        return notificationMapper.deleteNotification(notificationId) > 0;
    }
}
